<template>
  <div>
    <city-header/>
    <city-search :cityData="cityData" @searchChange="searchChangeHandler"/>
    <city-list :cityData="cityData" :isShow="isShowList"/>
  </div>
</template>

<script>
import axios from 'axios'
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
export default {
  name: 'City',
  mounted () {
    this.getData()
  },
  data () {
    return {
      cityData: {},
      isShowList: true
    }
  },
  methods: {
    getData () {
      axios.get('api/city.json')
        .then(this.response)
    },
    response (res) {
      res = res.data
      if (res.ret && res.data) {
        this.cityData = res.data
      } else {
        console.error('城市选择数据请求失败！')
      }
    },
    searchChangeHandler (flag) {
      this.isShowList = flag
    }
  },
  components: {
    CityHeader,
    CitySearch,
    CityList
  }
}
</script>

<style>
</style>
